Release 10.1A: OpenEdge Development:
Web Services


Temperature sample walk-through

TemperatureSample.p follows these steps to prepare, call, and process the output from a quote request (source code edited and formatted for clarity):

  1. Prompts for the requested zip code using the Enter Zip Code field:
  2. DEFINE VARIABLE fillin-1 AS CHARACTER LABEL "Enter Zip Code". 
    . 
    . 
    . 
    DEFINE FRAME fTemp 
        fillin-1 AT ROW 3 COLUMN 5 
        bgetTemp AT ROW 5 COLUMN 12 
        fillin-2 AT ROW 7 COLUMN 5 
        WITH SIDE-LABELS SIZE 45 BY 10 THREE-D.. 
    . 
    . 
    . 
    ENABLE ALL WITH FRAME fTemp. 
    

  3. Creates a Web service object in the 4GL:
  4. DEFINE VARIABLE hWebService AS HANDLE. 
    . 
    . 
    . 
    CREATE SERVER hWebService.  
    

  5. Connects to the Web service:
  6. hWebService:CONNECT("-WSDL 
             'http://www.xmethods.net/sd/2001/TemperatureService.wsdl' ").  
    IF  NOT hWebService:CONNECTED() THEN 
        MESSAGE "SERVER NOT CONNECTED" VIEW-AS ALERT-BOX. 
    

  7. Sets the handle to the port type in the WSDL where the Web service operation is defined and waits for the user to invoke the request:
  8. DEFINE VARIABLE hPortType AS HANDLE. 
    . 
    . 
    . 
    RUN TemperaturePortType SET hPortType ON SERVER hWebService NO-ERROR.  
    IF ERROR-STATUS:ERROR THEN 
        MESSAGE "Failed to create hPortType" VIEW-AS ALERT-BOX. 
    WAIT-FOR CLOSE OF CURRENT-WINDOW. 
    

  9. When the user clicks the getTemp button, TemperatureSample.p:
    1. Retrieves the zip code entered in the Enter Zip Code field:
    2. DEFINE VARIABLE cZipCode AS CHARACTER. 
      . 
      . 
      . 
      ON CHOOSE OF bgetTemp 
      DO: 
        cZipCode = fillin-1:SCREEN-VALUE. 
        . 
        . 
        . 
      

    3. Invokes the Web service getTemp operation by making a procedure call:
    4. DEFINE VARIABLE cTemp AS CHARACTER. 
      . 
      . 
      . 
      ON CHOOSE OF bgetTemp 
      DO: 
        cZipCode = fillin-1:SCREEN-VALUE. 
        RUN getTemp IN hPortType (INPUT cZipCode, OUTPUT cTemp) NO-ERROR. 
        . 
        . 
        . 
      

    5. If there are no errors, assigns the output value from the getTemp procedure call to the The Temp is field:
    6. ON CHOOSE OF bgetTemp 
      DO: 
        cZipCode = fillin-1:SCREEN-VALUE. 
        RUN getTemp IN hPortType (INPUT cZipCode, OUTPUT cTemp) NO-ERROR. 
        IF ERROR-STATUS:ERROR THEN 
        DO: 
          DO i = 1 TO ERROR-STATUS:NUM-MESSAGES: 
              MESSAGE ERROR-STATUS:GET-MESSAGE(i) VIEW-AS ALERT-BOX. 
          END. 
          IF VALID-HANDLE(ERROR-STATUS:ERROR-OBJECT-DETAIL) THEN 
            DO: 
              MESSAGE "Fault Code: " 
                  ERROR-STATUS:ERROR-OBJECT-DETAIL:SOAP-FAULT-CODE SKIP 
                "Fault String: " 
                  ERROR-STATUS:ERROR-OBJECT-DETAIL:SOAP-FAULT-STRING SKIP 
                "Fault Actor: " 
                  ERROR-STATUS:ERROR-OBJECT-DETAIL:SOAP-FAULT-ACTOR SKIP 
                "Error Type: "  
                  ERROR-STATUS:ERROR-OBJECT-DETAIL:TYPE 
              VIEW-AS ALERT-BOX. 
              IF VALID-HANDLE(ERROR-STATUS:ERROR-OBJECT-DETAIL 
                              :SOAP-FAULT-DETAIL) THEN 
                  MESSAGE  "Error Type: "  
                      ERROR-STATUS:ERROR-OBJECT-DETAIL 
                                  :SOAP-FAULT-DETAIL:TYPE   
                    "Fault Detail: " 
                      ERROR-STATUS:ERROR-OBJECT-DETAIL 
                                  :SOAP-FAULT-DETAIL:GET-SERIALIZED() 
                  VIEW-AS ALERT-BOX. 
            END.  
        END. 
        ELSE 
          fillin-2:SCREEN-VALUE = STRING(cTemp, "99").  
      END. 
      

    7. If there are errors, displays the error information:
    8. ON CHOOSE OF bgetTemp 
      DO: 
        cZipCode = fillin-1:SCREEN-VALUE. 
        RUN getTemp IN hPortType (INPUT cZipCode, OUTPUT cTemp) NO-ERROR. 
        IF ERROR-STATUS:ERROR THEN 
        DO: 
          DO i = 1 TO ERROR-STATUS:NUM-MESSAGES: 
              MESSAGE ERROR-STATUS:GET-MESSAGE(i) VIEW-AS ALERT-BOX. 
          END. 
          IF VALID-HANDLE(ERROR-STATUS:ERROR-OBJECT-DETAIL) THEN 
            DO: 
              MESSAGE "Fault Code: " 
                  ERROR-STATUS:ERROR-OBJECT-DETAIL:SOAP-FAULT-CODE SKIP 
                "Fault String: " 
                  ERROR-STATUS:ERROR-OBJECT-DETAIL:SOAP-FAULT-STRING SKIP 
                "Fault Actor: " 
                  ERROR-STATUS:ERROR-OBJECT-DETAIL:SOAP-FAULT-ACTOR SKIP 
                "Error Type: "  
                  ERROR-STATUS:ERROR-OBJECT-DETAIL:TYPE 
              VIEW-AS ALERT-BOX. 
              IF VALID-HANDLE(ERROR-STATUS:ERROR-OBJECT-DETAIL 
                              :SOAP-FAULT-DETAIL) THEN 
                  MESSAGE  "Error Type: "  
                      ERROR-STATUS:ERROR-OBJECT-DETAIL 
                                  :SOAP-FAULT-DETAIL:TYPE   
                    "Fault Detail: " 
                      ERROR-STATUS:ERROR-OBJECT-DETAIL 
                                  :SOAP-FAULT-DETAIL:GET-SERIALIZED() 
                  VIEW-AS ALERT-BOX. 
            END.  
        END. 
        ELSE 
          fillin-2:SCREEN-VALUE = STRING(cTemp, "99").  
      END. 
      

      Note that after displaying all the available error messages, it verifies that a SOAP fault caused the error by checking if a SOAP fault object is part of the error status (ERROR-STATUS:ERROR-OBJECT-DETAIL references it). After displaying the basic SOAP fault information, it further verifies that there is SOAP fault detail information by checking if a SOAP fault-detail object is part of the SOAP fault object data (ERROR-STATUS:ERROR-OBJECT-DETAIL:SOAP-FAULT-DETAIL references it) and displays any SOAP fault detail information that it references.

  10. Cleans up by running this code:
  11. DELETE PROCEDURE hPortType. 
    hWebService:DISCONNECT().  
    DELETE OBJECT hWebService. 
    

    which:

    1. Deletes the procedure object.
    2. Disconnects from the Web service.
    3. Deletes the Web service object.

Copyright © 2005 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095